package Example5;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

public class TJUTNewsObservable extends Observable {
    private List<String> newsList=new ArrayList<>();


    public void setNews(String newsItem){
        newsList.add(newsItem);
        setChanged();
        notifyObservers();
    }

    @Override
    public void notifyObservers() {
        for(String news:newsList){
            notifyObservers(news);
        }
        System.out.println("TJUTNewsObservable 已经所有的新闻消息发送给所有的观察者!");
    }

    @Override
    public String toString() {
        return "我是TJUT新闻Observable";
    }
}
